//
//  KeyBoardView.swift
//  E-CycleForShop
//
//  Created by enghou on 17/3/11.
//  Copyright © 2017年 xyxorigation. All rights reserved.
//

import UIKit

class KeyBoardView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        for i in 1 ..< 13 {
            let button = numberView(number: i)
            self.addSubview(button)
        }
        let separator1 = UIView.init(frame: CGRect.init(x: frame.size.width / 3, y: 0, width: YXWidthScale, height: frame.size.height))
        separator1.backgroundColor = UIColor.colorWithHexString(hex: "f2f2f2")
        self.addSubview(separator1)
        let separator2 = UIView.init(frame: CGRect.init(x: 2 * frame.size.width / 3, y: 0, width: YXWidthScale, height: frame.size.height))
        separator2.backgroundColor = UIColor.colorWithHexString(hex: "f2f2f2")
        self.addSubview(separator2)
        
        let separator3 = UIView.init(frame: CGRect.init(x: 0, y: frame.size.height / 4, width: frame.size.width, height: YXHeightScale))
        separator3.backgroundColor = UIColor.colorWithHexString(hex: "f2f2f2")
        self.addSubview(separator3)
        
        let separator4 = UIView.init(frame: CGRect.init(x: 0, y: frame.size.height / 2, width: frame.size.width, height: YXHeightScale))
        separator4.backgroundColor = UIColor.colorWithHexString(hex: "f2f2f2")
        self.addSubview(separator4)
        
        let separator5 = UIView.init(frame: CGRect.init(x: 0, y: 3 * frame.size.height / 4, width: frame.size.width, height: YXHeightScale))
        separator5.backgroundColor = UIColor.colorWithHexString(hex: "f2f2f2")
        self.addSubview(separator5)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func numberView(number : Int) -> UIButton {
        let btn = UIButton.init(type: .custom)
        let wid = YXDeviceWidth / 3
        let image = UIImage.image(color: UIColor.colorWithHexString(hex: "f2f2f2"), size: CGSize.init(width: wid, height: 40))
        btn.setBackgroundImage(image, for: .highlighted)
        btn.setTitleColor(UIColor.black, for: .normal)
        if number == 10 {
            btn.setTitle(".", for: .normal)
        } else if number == 11 {
            btn.setTitle("0", for: .normal)
        } else if number == 12 {
            btn.setTitle("退格", for: .normal)
        } else {
            btn.setTitle(String(number), for: .normal)
        }
        
        let height = self.bounds.size.height / 4
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 60 * YXWidthScale)
        btn.frame = CGRect.init(x: CGFloat((number - 1) % 3) * wid, y: CGFloat((number - 1) / 3) * height, width: wid, height: height)
//        btn.layer.borderWidth = YXHeightScale
//        btn.layer.borderColor = UIColor.colorWithHexString(hex: "f2f2f2").cgColor
        return btn
    }
    
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
